IF OBJECT_ID('dbo.GetPreAwardManagers') IS NOT NULL
BEGIN
    DROP PROCEDURE dbo.GetPreAwardManagers
    IF OBJECT_ID('dbo.GetPreAwardManagers') IS NOT NULL
        PRINT '<<< FAILED DROPPING PROCEDURE dbo.GetPreAwardManagers >>>'
    ELSE
        PRINT '<<< DROPPED PROCEDURE dbo.GetPreAwardManagers >>>'
END
go
-- =======================================================================
-- Procedure Name: dbo.GetPreAwardManagers
--
-- Author:      Kevin Cashman, Parallax Consulting LLC
--
-- Create date: 9/11/2007
--
-- Description: Returns list of CSCRCaseManagers from UDF table
--
-- Parameters:  None
--              
-- Returns:     INT, 0=Success, -1=Error
--
-- SampleCall:
-- EXECUTE dbo.GetPreAwardManagers()
--
--------------------------------------------------------------------------
-- Date        Initials  Modification
--------------------------------------------------------------------------
-- 9/11/07     KC        Created
-- 9/20/07     KC        Added @ActivityType, changed source of loginid
-- 9/28/07     KC        Fixed FwkDomainUserId
-- 11/2/07     KC        Added @Institution
-- 12/20/07	KC		Fixed ActivityDescription from ActivityCode
--
-- =======================================================================
CREATE PROCEDURE dbo.GetPreAwardManagers
     (@ActivityType      VARCHAR(60)=NULL,
     @Institution        INT=NULL
     )
AS
BEGIN
     /*  Returned Fields for Dropdown
     --------------------------------
     PreAwardManagerId        INT
     PreAwardManagerName      VARCHAR             
     PreAwardManager          VARCHAR
     */

     -- Initial Settings
     SET NOCOUNT ON
     
     -- Declare Local Variables
     DECLARE   @Error            INT,
               @RowCount         INT
               
     -- Result Query    
     SELECT DISTINCT PreAwardManagerId AS PreAwardManagerId,
               PreAwardManagerName AS PreAwardManagerName,
               PreAwardManager AS PreAwardManager
     FROM      dbo.AgrAgreement_Info AI
     WHERE     (@ActivityType IS NULL OR AI.ActivityDescription LIKE @ActivityType + '%') AND
               (@Institution IS NULL OR AI.InstitutionId = @Institution) AND
               PreAwardManager IS NOT NULL AND PreAwardManager != ''
     ORDER BY PreAwardManagerName
     
     SELECT @Error=@@ERROR,@RowCount=@@ROWCOUNT
     IF @Error!=0
          RETURN -1

     -- Return Success
     RETURN 0
     
END
go

IF OBJECT_ID('dbo.GetPreAwardManagers') IS NOT NULL
    PRINT '<<< CREATED PROCEDURE dbo.GetPreAwardManagers >>>'
ELSE
    PRINT '<<< FAILED CREATING PROCEDURE dbo.GetPreAwardManagers >>>'
go

GRANT EXECUTE ON dbo.GetPreAwardManagers TO InsightReport,Insight
go
